package me.zhengjie.modules.transfer.factory.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.account.domain.AccountAc50;
import me.zhengjie.modules.account.domain.AccountAc51;
import me.zhengjie.modules.account.mapper.AccountCommonMapper;
import me.zhengjie.modules.account.service.AccountAa02Service;
import me.zhengjie.modules.account.service.AccountAc50Service;
import me.zhengjie.modules.account.service.AccountAc51Service;
import me.zhengjie.modules.sequence.domain.Sequence;
import me.zhengjie.modules.sequence.service.SequenceService;
import me.zhengjie.modules.transfer.domain.*;
import me.zhengjie.modules.transfer.factory.service.*;
import me.zhengjie.modules.transfer.factory.vo.*;
import me.zhengjie.modules.transfer.service.*;
import me.zhengjie.tool.*;
import me.zhengjie.vo.Constant;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 机关转移
 */
@Data
@Service
@RequiredArgsConstructor
public class TransferInformationIc66ServiceImpl implements TransferInformationIc66Service {


    private final TransferInformationService transferInformationService;
    private final TransferPersonService transferPerson;
    private final TransOutDealService transOutDealService;
    private final TransCheckService transCheckService;
    private final AccountAc50Service accountAc50Service;
    private final AccountAc51Service accountAc51Service;
    private final AccountCommonMapper accountCommonMapper;
    private final TransferIc66Service transferIc66Service;
    private final TransferIc67Service transferIc67Service;
    private final TransferIc68Service transferIc68Service;
    private final SequenceService sequenceService;
    private final AccountAa02Service accountAa02Service;

    private final TransferProcessService transferProcessService;


    /**
     * 人员编号
     */
    protected String aac001;

    /**
     * 转出人员编号
     */
    protected String aac319;

    /**
     * 险种类型
     */
    protected String aae140;

    /**
     * 对方险种
     */
    protected String aae241;

    /**
     * 转移数据来源
     */
    protected String aac306;

    /**
     * 上传方经办人
     */
    protected String aae736;

    /**
     * 上传方经办时间
     */
    protected String aae739;

    /**
     * 联网下载标志
     */
    protected String aae732;
    /**
     * 业务环节
     */
    protected String aae803;

    /**
     * 业务环节状态
     */
    protected String aae158;

    /**
     * 户籍地址
     */
    protected String aac010;

    /**
     * 业务类型编码
     */
    protected String aaa121;
    /**
     * 人员信息
     */
    protected TransferPersonInfo transferPersonInfo;


    /**
     * 转移制度方向
     */
    protected String aic113;

    /**
     * 联系函编号
     */
    protected String aae270;

    /**
     * 银行类别
     */
    protected String aaf200;
    /**
     * 地方银行类别
     */
    protected String aaf216;
    /**
     * 地方银行类别名称
     */
    protected String aaf217;
    /**
     * 对方行政区划
     */
    protected String aab299;

    /**
     * 首次参保地缴费时间
     */
    protected String aab305;

    /**
     * 信息表主键id
     */
    protected String infoKey;

    /**
     * 信息表明细id
     */
    protected String detailsKey;

    /**
     * 信息表其他表id
     */
    protected String othersKey;

    /**
     * 转移基金金额
     */
    protected BigDecimal money;

    /**
     * 被确认标志（指信息表是否已经生成缴费或个人账户信息）
     */
    protected String aae733;

    /**
     * 信息表
     */
    protected InformationInfo informationInfo;

    /**
     * 信息表附表
     */
    protected List<InformationDetailInfo> informationDetailInfos = new ArrayList<>();

    /**
     * 信息表其他附表
     */
    protected List<InformationOtherInfo> informationOtherInfos = new ArrayList<>();

    /**
     * 转入转移基金信息
     */
    protected List<MyMap> funds = new ArrayList<>();

    /**
     * 是否跨省转移
     */
    protected boolean transProvincal;


    /**
     * 是否是信息表特权修改
     */
    protected String transModifyInfo;

    /**
     * 是否是历史补录
     */
    protected String transConanctInfo;

    /**
     * 本地缴费记录
     */
    protected List<Map> paymentList;

    /**
     * 是否是说明
     */
    protected String aae013;

    /**
     * 业务日志号
     */
    protected String aaz002;
    /**
     * 转出保存信息表
     *
     * @param map
     * @return
     */
    @Override
    public Map transOutInfo(MyMap map) {
        this.aac306=Constant.AAC306_1_BD;
        String aac001 = map.getAsString("aac001");

        List<Map> paymentList = (List<Map>) map.get("paymentList");
        NPETool.isEmptyThrowException(aac001, "人员编号");
        NPETool.isEmptyThrowException(paymentList, "缴费明细");

        NPETool.isEmptyThrowException(map.getAsString("aic113"), "转移制度方向");

        MyMap myMap = transferPerson.xxbAae140Aae241(map.getAsString("aic113"));
         aae140 = myMap.getAsString("aae140");
         aae241 = myMap.getAsString("aae241");
        NPETool.isEmptyThrowException(aae140, "险种类型");
        NPETool.isEmptyThrowException(aae140, "转出险种类型");


        this.aaz002=map.getAsString("aaz002");

        //1、获取人员基本信息
        MyMap transferPerson1 = transferPerson.getTransferPerson(aac001, aae140);

        //初始化信息表信息
        TransferInformationIc66(map);

        map.put("aac306", this.aac306);
        //2、组装人员信息
        transferPersonInfoCreate(transferPerson1, map);

        //3、转出通用校验
        transferInformationService.transferOutCheck(aac001, aae140, aae241, aac306, aic113);
        //4、创建信息表
        transferOut();
        //5、信息表规则校验
        transferInCheck();
        //6、保存信息表
        saveInformation();


        map.put("bae038","IC66");
        //7、保存流程信息
        transferProcessService.createProcessTransfer(map);

        return transferPerson1;
    }

    /**
     * 转出预览生成信息表
     *
     * @param map
     * @return
     */
    @Override
    public Map informationPreview(MyMap map) {
        this.aac306=Constant.AAC306_1_BD;


        String aac001 = map.getAsString("aac001");
        NPETool.isEmptyThrowException(aac001, "人员编号");
        NPETool.isEmptyThrowException(map.getAsString("aic113"), "转移制度方向");

        MyMap myMap = transferPerson.xxbAae140Aae241(map.getAsString("aic113"));
         aae140 = myMap.getAsString("aae140");
         aae241 = myMap.getAsString("aae241");
        NPETool.isEmptyThrowException(aae140, "险种类型");
        NPETool.isEmptyThrowException(aae140, "转出险种类型");


        NPETool.isEmptyThrowException(map.get("paymentListXXB"), "缴费明细");

        List<Map> ac50s = (List<Map>) map.get("ac50");
        List<Map> ac51s = (List<Map>) map.get("ac51");
        List<Map> ac52s = (List<Map>) map.get("ac52");



        //1、获取人员基本信息
        MyMap transferPerson1 = transferPerson.getTransferPerson(aac001, aae140);

        //初始化信息表信息
        TransferInformationIc66(map);

        map.put("aac306", this.aac306);
        //2、组装人员信息
        transferPersonInfoCreate(transferPerson1,map);

        //3、转出通用校验
        transferInformationService.transferOutCheck(aac001, aae140, aae241, aac306, aic113);
        //5、预览生成信息表
        transferOutPrivew(ac50s, ac51s, ac52s);
        //6、信息表规则校验
        // transferInCheck();


        Map infromationMap = new HashMap();
        //    transferInformationService.packageParam( informationInfo, informationDetailInfos, informationOtherInfos, transferPersonInfo, funds, aac306, aaf200, aaf216, aaf217, aae013, aae140, aae241,this.infoKey,this.detailsKey,this.othersKey);


        infromationMap.put("information", informationInfo);
        infromationMap.put("informationDetail", informationDetailInfos);
        infromationMap.put("informationOtherInfos", informationOtherInfos);


        System.out.println(JSON.toJSONString(infromationMap));
        return infromationMap;
    }

    /**
     * 转出登记回退
     * @param aaz002
     * @return
     */
    @Override
    public Map transOutRevoke(String aaz002) {
        HashMap map = new HashMap<>();
        map.put("aaz002",aaz002);
        transferIc66Service.removeByMap(map);
        transferIc67Service.removeByMap(map);
        transferIc68Service.removeByMap(map);

        return null;
    }



    public void TransferInformationIc66(MyMap myMap) {

        this.aac001 = myMap.getAsString("aac001");
        this.aac319 = myMap.getAsString("aac319");
        this.aae736 = myMap.getAsString("aae736");
        this.aae739 = myMap.getAsString("aae739");
        this.aae732 = myMap.getAsString("aae732");
        this.aac010 = myMap.getAsString("aac010");


        this.aic113 = myMap.getAsString("aic113");
        this.aae270 = myMap.getAsString("aae270");
        this.aac319 = myMap.getAsString("aac319");
        this.aab305 = myMap.getAsString("aab305");
        this.paymentList = new ArrayList<>();

        if (!ValidateUtil.isEmpty(myMap.get("paymentList"))) {
            paymentList.addAll((List<Map>) myMap.get("paymentList"));
        }
        if (Constant.AAC306_2_YD.equals(this.aac306)) {
            if (!ValidateUtil.isEmpty(myMap.getAsString("fund")) && !"[]".equals(myMap.getAsString("fund"))) {
                List<MyMap> funds_1 = ListUtil.list2MyMapList(JSON.parseArray(myMap.getAsString("fund"), List.class));
                this.funds.addAll(funds_1);
                this.aae733 = Constant.AAE733_1_S;
            } else {
                this.aae733 = Constant.AAE733_0_F;
                if (!ValidateUtil.isEmpty(myMap.get("info"))) {
                    MyMap infoMyMap = MyMap.convertToMap(myMap.getAsString("info"));
                    //如果只转视同，则默认aae733为1，这样才会写入ac08
                    if (!ValidateUtil.isEmpty(infoMyMap.get("aic102"))) {
                        if (BigDecimal.ZERO.compareTo(infoMyMap.getAsBigDecimal("aic102")) == 0) {
                            this.aae733 = Constant.AAE733_1_S;
                        }
                    }
                }
            }
            //外部参数干预 确认标志 （特权维护直接确认）
            if (!ValidateUtil.isEmpty(myMap.getAsString("aae733"))) {
                this.aae733 = myMap.getAsString("aae733");

            }

        } else {
            Map orginfoin = (Map) myMap.get("orginfoin");
            if (!ValidateUtil.isEmpty(orginfoin)) {
                this.aaf216 = (String) orginfoin.get("aaf216");
                this.aaf200 = (String) orginfoin.get("aaf200");
                this.aaf217 = (String) orginfoin.get("aaf217");
                this.aae270 = (String) orginfoin.get("aae270");
                //转出 对方联系函aab301 是转入地行政区划
                this.aab299 = (String) orginfoin.get("aab301");

            }
        }

        this.infoKey = "AAZ756";
        this.detailsKey = "AAZ652";
        this.aae803 = Constant.AAE803_T1102_JGYLBXZYXXB;
        if (!ValidateUtil.isEmpty(myMap.getAsString("transModifyInfo"))) {
            this.transModifyInfo = "1";
        }

        if (!ValidateUtil.isEmpty(myMap.getAsString("transConanctInfo"))) {
            this.transConanctInfo = "1";
        }

        if (!ValidateUtil.isEmpty(myMap.getAsString("aae013"))) {
            this.aae013 = myMap.getAsString("aae013");
        }

        if (Constant.AAC306_2_YD.equals(this.aac306)) {
            initInInformation(myMap);
        }
    }

    //转入初始化信息表
    public void initInInformation(MyMap myMap) {

        MyMap info = JSONObject.parseObject(myMap.getAsString("info"), MyMap.class);
        NPETool.isEmptyThrowException(info, "信息表信息");

        String aab301 = info.getAsString("aab301");
        NPETool.isEmptyThrowException(aab301, "转出地行政区划");

        String aab299 = info.getAsString("aab299");
        NPETool.isEmptyThrowException(aab299, "转入地行政区划");

        String aac006 = info.getAsString("aac006");
        NPETool.isEmptyThrowException(aac006, "出生日期");

        if (aab301.substring(0, 2).equals(aab299.substring(0, 2))) {
            this.transProvincal = false;
            //省内转移 直接确认 生成缴费和账户
            this.aae733 = Constant.AAE733_1_S;
        } else {
            this.transProvincal = true;
        }
        this.aac319 = info.getAsString("aac319");

        List<MyMap> detailList = ListUtil.list2MyMapList(JSONObject.parseObject(myMap.getAsString("infoDetails"), List.class));

        info.put("aab300", "");//转出地社保经办机构 todo  转出机构信息
        info.put("aaa146", "");//转入地社保经办机构
        this.informationInfo = new Ic90Info(info);

        InformationDetailInfo informationDetailInfo;
        int aaz751 = 0;
        String aae013 = "";
        for (MyMap map : detailList) {
            map.put("aac001", this.aac001);
            map.put("aaz751", aaz751);
            aae013 = map.getAsString("aae013");
            if (!ValidateUtil.isEmpty(aae013) && (aae013.contains("null") || aae013.contains("NULL"))) {
                aae013 = aae013.replaceAll("null", "").replaceAll("NULL", "");
                map.put("aae013", aae013);
            }
            informationDetailInfo = new Ic91Info(map);
            this.informationDetailInfos.add(informationDetailInfo);
            aaz751++;
        }

    }

    /**
     * 信息表校验
     */
    public void transferInCheck() {

        this.money = ValidateUtil.isEmpty(((Ic90Info) informationInfo).getAic102())
                ? BigDecimal.ZERO : ((Ic90Info) informationInfo).getAic102();


        NPETool.isEmptyThrowException(this.informationInfo, "信息表信息");
        NPETool.isEmptyThrowException(this.informationDetailInfos, "信息表明细信息");

        String aae270new = this.informationInfo.getAae270();
        NPETool.isEmptyThrowException(aae270new, "联系函编号");
        // 1.校验人员正常参保
        //  TransCheckService.checkAac008(this.getAac001(), this.getAae241());
        // 2.校验转入申请
        if (!(informationInfo instanceof Ic96Info) && !("1".equals(this.transConanctInfo)) && !("1".equals(this.transModifyInfo))) { // 过滤军转 军转没有转入申请
            //       TransCheckService.checkApplication(aae270new, this.getAae241(), this.getAae140());
        }
        // 3.校验是否已办理转入
        MyMap myMap = new MyMap();
        myMap.put("aae270", aae270new);
        myMap.put("aac001", this.aac001);
        myMap.put("aac306", Constant.AAC306_2_YD);
        if (!"1".equals(this.transModifyInfo) && !("1".equals(this.transConanctInfo))) {
            List<Map> transferProcess = new ArrayList<>();
//                List<Map> transferProcess = RepositoryRegister.transferRepository().queryProcessInfo(myMap);
            if (!ValidateUtil.isEmpty(transferProcess)) {

                for (Map map : transferProcess) {
                    if (Constant.AAE803_T0102_ZYJXXXB.equals(map.get("aae803")) || Constant.AAE803_T0502_ZRDFQDLSZHZ.equals(map.get("aae803"))
                            || Constant.AAE803_T0601_JRTYYLBXCBJFPZHXXB.equals(map.get("aae803")) || Constant.AAE803_T0703_CXJMYLBXZRCZZGYLBXXXB.equals(map.get("aae803"))
                            || Constant.AAE803_T0802_CZZGYLBXZRCXJMYLBXXXB.equals(map.get("aae803")) || Constant.AAE803_T0902_CXJBYLBXKDQZYSPB.equals(map.get("aae803"))
                            || Constant.AAE803_T1102_JGYLBXZYXXB.equals(map.get("aae803")) || Constant.AAE803_T1201_JGSYYLBXCZCTRYZYXXB.equals(map.get("aae803"))
                            || Constant.AAE803_T1302_JGSYYLBXZYNJZYXXB.equals(map.get("aae803"))) {
                        throw new IllegalArgumentException("当前联系函已办理了转入");
                    }
                }
            }
        }


        if (ValidateUtil.isNotEmpty(this.funds)) {
            BigDecimal aae019 = BigDecimal.ZERO;
            for (MyMap fund : this.funds) {
                aae019 = aae019.add(fund.getAsBigDecimal("aae019"));
            }
            if (!ValidateUtil.isEmpty(aae019)) {
                if (aae019.compareTo(money) != 0) {
                    throw new IllegalArgumentException("财务到账金额和转移金额不一致！");
                }
            }
        }

        transCheckService.checkInformationOfStaff(informationInfo, informationDetailInfos);
        transCheckService.checkInformationOfStaffDetails(informationInfo, informationDetailInfos);

    }


    public void transferOut() {
        this.informationInfo = new InformationInfo();//信息表信息
        this.informationDetailInfos = new ArrayList<>();//信息表明细信息
        this.informationOtherInfos = new ArrayList<>();//附表信息
        createInformationOfIc66();
    }


    /**
     * 转出预览生成信息表
     */

    public void transferOutPrivew(List<Map> ac50s, List<Map> ac51s, List<Map> ac52s) {

        this.informationInfo = new InformationInfo();//信息表信息
        this.informationDetailInfos = new ArrayList<>();//信息表明细信息
        this.informationOtherInfos = new ArrayList<>();//附表信息

        createInformationOfIc66Preview(ac51s, ac52s);
    }

    /**
     * 保存
     */

    public Map saveInformation() {

        Map ic90 = BeanUtil.beanToMap(this.informationInfo);
        TransferIc66 transferIc66 = new TransferIc66();
        Sequence sequence_aaz701 = new Sequence();
        sequence_aaz701.setName("aaz701");
        String aaz701 = sequenceService.nextSequence(sequence_aaz701);
        String aae036= DateUtil.getCurrentTime("yyyyMMddHHmmss");

        transferIc66.setAaz701(aaz701);
        transferIc66.setAaz341(ValidateUtil.isEmpty(ic90.get("aaz341")) ? null : ic90.get("aaz341").toString());
        transferIc66.setAab301(ValidateUtil.isEmpty(ic90.get("aab301")) ? null : ic90.get("aab301").toString());
        transferIc66.setAab299(ValidateUtil.isEmpty(ic90.get("aab299")) ? null : ic90.get("aab299").toString());
        transferIc66.setAae270(ValidateUtil.isEmpty(ic90.get("aae270")) ? null : ic90.get("aae270").toString());
        transferIc66.setAae405(ValidateUtil.isEmpty(ic90.get("aae405")) ? null : ic90.get("aae405").toString());
        transferIc66.setAae140(this.aae140);
        transferIc66.setAae241(this.aae241);
        transferIc66.setAac319(ValidateUtil.isEmpty(ic90.get("aac319")) ? null : ic90.get("aac319").toString());
        transferIc66.setAac001(ValidateUtil.isEmpty(ic90.get("aac001")) ? null : ic90.get("aac001").toString());
        transferIc66.setAac002(ValidateUtil.isEmpty(ic90.get("aac002")) ? null : ic90.get("aac002").toString());
        transferIc66.setAac003(ValidateUtil.isEmpty(ic90.get("aac003")) ? null : ic90.get("aac003").toString());
        transferIc66.setAac004(ValidateUtil.isEmpty(ic90.get("aac004")) ? null : ic90.get("aac004").toString());
        transferIc66.setAac006(ValidateUtil.isEmpty(ic90.get("aac006")) ? null : new BigDecimal(ic90.get("aac006").toString()));
        transferIc66.setAac010(ValidateUtil.isEmpty(ic90.get("aac010")) ? null : ic90.get("aac010").toString());
        transferIc66.setAae473(ValidateUtil.isEmpty(ic90.get("aae473")) ? null : ic90.get("aae473").toString());
        transferIc66.setAac028(ValidateUtil.isEmpty(ic90.get("aac028")) ? null : ic90.get("aac028").toString());
        transferIc66.setAae035(ValidateUtil.isEmpty(ic90.get("aae035")) ? null : new BigDecimal(ic90.get("aae035").toString()));
        transferIc66.setAic113(ValidateUtil.isEmpty(ic90.get("aic113")) ? null : ic90.get("aic113").toString());
        transferIc66.setAae173(ValidateUtil.isEmpty(ic90.get("aae173")) ? null : ic90.get("aae173").toString());
        transferIc66.setAab004(ValidateUtil.isEmpty(ic90.get("aab004")) ? null : ic90.get("aab004").toString());
        transferIc66.setAac007(ValidateUtil.isEmpty(ic90.get("aac007")) ? null : new BigDecimal(ic90.get("aac007").toString()));
        transferIc66.setAab305(ValidateUtil.isEmpty(ic90.get("aab305")) ? null : new BigDecimal(ic90.get("aab305").toString()));
        transferIc66.setAac049(ValidateUtil.isEmpty(ic90.get("aac049")) ? null : new BigDecimal(ic90.get("aac049").toString()));
        transferIc66.setAac032(ValidateUtil.isEmpty(ic90.get("aac032")) ? null : new BigDecimal(ic90.get("aac032").toString()));
        transferIc66.setAae030(ValidateUtil.isEmpty(ic90.get("aae030")) ? null : new BigDecimal(ic90.get("aae030").toString()));
        transferIc66.setAae031(ValidateUtil.isEmpty(ic90.get("aae031")) ? null : new BigDecimal(ic90.get("aae031").toString()));
        transferIc66.setAae201(ValidateUtil.isEmpty(ic90.get("aae201")) ? null : new BigDecimal(ic90.get("aae201").toString()));
        transferIc66.setAic093(ValidateUtil.isEmpty(ic90.get("aic093")) ? null : new BigDecimal(ic90.get("aic093").toString()));
        transferIc66.setAic089(ValidateUtil.isEmpty(ic90.get("aic089")) ? null : new BigDecimal(ic90.get("aic089").toString()));
        transferIc66.setAic082(ValidateUtil.isEmpty(ic90.get("aic082")) ? null : new BigDecimal(ic90.get("aic082").toString()));
        transferIc66.setAic083(ValidateUtil.isEmpty(ic90.get("aic083")) ? null : new BigDecimal(ic90.get("aic083").toString()));
        transferIc66.setAic084(ValidateUtil.isEmpty(ic90.get("aic084")) ? null : new BigDecimal(ic90.get("aic084").toString()));
        transferIc66.setAic102(ValidateUtil.isEmpty(ic90.get("aic102")) ? null : new BigDecimal(ic90.get("aic102").toString()));
        transferIc66.setAaa146(ValidateUtil.isEmpty(ic90.get("aaa146")) ? null : ic90.get("aaa146").toString());
        transferIc66.setAab300(ValidateUtil.isEmpty(ic90.get("aab300")) ? null : ic90.get("aab300").toString());
        transferIc66.setAad019(ValidateUtil.isEmpty(ic90.get("aad019")) ? null : new BigDecimal(ic90.get("aad019").toString()));
        transferIc66.setAae062(ValidateUtil.isEmpty(ic90.get("aae062")) ? null : new BigDecimal(ic90.get("aae062").toString()));
        transferIc66.setAae733(ValidateUtil.isEmpty(ic90.get("aae733")) ? null : ic90.get("aae733").toString());
        transferIc66.setAae736(ValidateUtil.isEmpty(ic90.get("aae736")) ? null : ic90.get("aae736").toString());
        transferIc66.setAae739(ValidateUtil.isEmpty(ic90.get("aae739")) ? null : new BigDecimal(ic90.get("aae739").toString()));
        transferIc66.setAac067(ValidateUtil.isEmpty(ic90.get("aac067")) ? null : ic90.get("aac067").toString());

        transferIc66.setAaz159(ValidateUtil.isEmpty(ic90.get("aaz159")) ? null : ic90.get("aaz159").toString());
        transferIc66.setAae732(ValidateUtil.isEmpty(ic90.get("aae732")) ? null : ic90.get("aae732").toString());
        transferIc66.setAae730(ValidateUtil.isEmpty(ic90.get("aae730")) ? null : ic90.get("aae730").toString());
        transferIc66.setAae013(ValidateUtil.isEmpty(ic90.get("aae013")) ? null : ic90.get("aae013").toString());
        transferIc66.setAae011(this.transferPersonInfo.getAae011());
        transferIc66.setAae036(new BigDecimal(aae036));
        transferIc66.setAab359(this.transferPersonInfo.getAab359());
        transferIc66.setAac306(this.aac306);
        transferIc66.setAaz002(this.aaz002);


        ArrayList<TransferIc67> listIc91 = new ArrayList<>();

        Sequence sequence_aaz652 = new Sequence();
        sequence_aaz652.setName("aaz652");
        Long aaz652 =  Long.valueOf(sequenceService.nextSequence(sequence_aaz652)+"000");

        for (InformationDetailInfo informationDetailInfo : this.informationDetailInfos) {
            TransferIc67 transferIc67 = new TransferIc67();
            Map ic91 = BeanUtil.beanToMap(informationDetailInfo);

            transferIc67.setAaz702(aaz652.toString());
            transferIc67.setAaz341(ValidateUtil.isEmpty(ic90.get("aaz341")) ? null : ic90.get("aaz341").toString());
            transferIc67.setAac319(ValidateUtil.isEmpty(ic91.get("aac319")) ? null : ic91.get("aac319").toString());
            transferIc67.setAac001(ValidateUtil.isEmpty(ic91.get("aac001")) ? null : ic91.get("aac001").toString());
            transferIc67.setAab301(ValidateUtil.isEmpty(ic91.get("aab301")) ? null : ic91.get("aab301").toString());
            transferIc67.setAab299(ValidateUtil.isEmpty(ic91.get("aab299")) ? null : ic91.get("aab299").toString());
            transferIc67.setAab300(ValidateUtil.isEmpty(ic91.get("aab300")) ? null : ic91.get("aab300").toString());
            transferIc67.setAae001(ValidateUtil.isEmpty(ic91.get("aae001")) ? null : new BigDecimal(ic91.get("aae001").toString()));
            transferIc67.setAae041(ValidateUtil.isEmpty(ic91.get("aae041")) ? null : new BigDecimal(ic91.get("aae041").toString()));
            transferIc67.setAae042(ValidateUtil.isEmpty(ic91.get("aae042")) ? null : new BigDecimal(ic91.get("aae042").toString()));
            transferIc67.setAae180(ValidateUtil.isEmpty(ic91.get("aae180")) ? null : new BigDecimal(ic91.get("aae180").toString()));
            transferIc67.setAae202(ValidateUtil.isEmpty(ic91.get("aae202")) ? null : new BigDecimal(ic91.get("aae202").toString()));
            transferIc67.setAaa041(ValidateUtil.isEmpty(ic91.get("aaa041")) ? null : new BigDecimal(ic91.get("aaa041").toString()));
            transferIc67.setAaa043(ValidateUtil.isEmpty(ic91.get("aaa043")) ? null : new BigDecimal(ic91.get("aaa043").toString()));
            transferIc67.setAaa042(ValidateUtil.isEmpty(ic91.get("aaa042")) ? null : new BigDecimal(ic91.get("aaa042").toString()));
            transferIc67.setAae381(ValidateUtil.isEmpty(ic91.get("aae381")) ? null : new BigDecimal(ic91.get("aae381").toString()));
            transferIc67.setAae264(ValidateUtil.isEmpty(ic91.get("aae264")) ? null : new BigDecimal(ic91.get("aae264").toString()));
            transferIc67.setAae269(ValidateUtil.isEmpty(ic91.get("aae269")) ? null : new BigDecimal(ic91.get("aae269").toString()));
            transferIc67.setAae265(ValidateUtil.isEmpty(ic91.get("aae265")) ? null : new BigDecimal(ic91.get("aae265").toString()));
            transferIc67.setAae382(ValidateUtil.isEmpty(ic91.get("aae382")) ? null : new BigDecimal(ic91.get("aae382").toString()));
            transferIc67.setAae273(ValidateUtil.isEmpty(ic91.get("aae273")) ? null : new BigDecimal(ic91.get("aae273").toString()));
            transferIc67.setAaz701(new BigDecimal(aaz701));
            transferIc67.setAaz159(ValidateUtil.isEmpty(ic90.get("aaz159")) ? null : ic90.get("aaz159").toString());
            transferIc67.setAaz751(ValidateUtil.isEmpty(ic91.get("aaz751")) ? null : ic91.get("aaz751").toString());
            transferIc67.setAae013(ValidateUtil.isEmpty(ic91.get("aae013")) ? null : ic91.get("aae013").toString());
            transferIc67.setAae011(this.transferPersonInfo.getAae011());
            transferIc67.setAae036(new BigDecimal(aae036));
            transferIc67.setAab359(this.transferPersonInfo.getAab359());
            transferIc67.setAaz002(this.aaz002);
            listIc91.add(transferIc67);
            aaz652++;

        }

        ArrayList<TransferIc68> listIc68 = new ArrayList<>();
        for (InformationOtherInfo informationOtherInfo : this.informationOtherInfos) {
            TransferIc68 transferIc68 = new TransferIc68();
            Map ic68 = BeanUtil.beanToMap(informationOtherInfo);

            transferIc68.setAaz703(aaz652.toString());
            transferIc68.setAaz341(ValidateUtil.isEmpty(ic90.get("aaz341")) ? null : ic90.get("aaz341").toString());
            transferIc68.setAab301(ValidateUtil.isEmpty(ic68.get("aab301")) ? null : ic68.get("aab301").toString());
            transferIc68.setAac319(ValidateUtil.isEmpty(ic68.get("aac319")) ? null : ic68.get("aac319").toString());
            transferIc68.setAac001(ValidateUtil.isEmpty(ic90.get("aac001")) ? null : ic90.get("aac001").toString());
            transferIc68.setAac003(ValidateUtil.isEmpty(ic90.get("aac003")) ? null : ic90.get("aac003").toString());
            transferIc68.setAae001(ValidateUtil.isEmpty(ic68.get("aae001")) ? null : new BigDecimal(ic68.get("aae001").toString()));
            transferIc68.setAae041(ValidateUtil.isEmpty(ic68.get("aae041")) ? null : new BigDecimal(ic68.get("aae041").toString()));
            transferIc68.setAae042(ValidateUtil.isEmpty(ic68.get("aae042")) ? null : new BigDecimal(ic68.get("aae042").toString()));
            transferIc68.setAae180(ValidateUtil.isEmpty(ic68.get("aae180")) ? null : new BigDecimal(ic68.get("aae180").toString()));
            transferIc68.setAaa015(ValidateUtil.isEmpty(ic68.get("aaa015")) ? null : new BigDecimal(ic68.get("aaa015").toString()));
            transferIc68.setAae062(ValidateUtil.isEmpty(ic68.get("aae062")) ? null : new BigDecimal(ic68.get("aae062").toString()));
            transferIc68.setAae036(new BigDecimal(aae036));
            transferIc68.setAaz159(ValidateUtil.isEmpty(ic90.get("aaz159")) ? null : ic90.get("aaz159").toString());
            transferIc68.setAae013(ValidateUtil.isEmpty(ic68.get("aae013")) ? null : ic68.get("aae013").toString());
            transferIc68.setAae011(this.transferPersonInfo.getAae011());
            transferIc68.setAab359(this.transferPersonInfo.getAab359());
            transferIc68.setAaz002(this.aaz002);
            listIc68.add(transferIc68);
            aaz652++;

        }

        transferIc66Service.save(transferIc66);

        transferIc67Service.saveBatch(listIc91);

        transferIc68Service.saveBatch(listIc68);

        return null;
    }




    /**
     * 创建信息表
     */
    private void createInformationOfIc66() {
        //后台根据账户类型判断 无需前台传入
        this.aae803 = Constant.AAE803_T1102_JGYLBXZYXXB;
        QueryWrapper<AccountAc50> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("aaz159", this.transferPersonInfo.getAaz159());
        queryWrapper.eq("aac001", this.transferPersonInfo.getAac001());
        queryWrapper.eq("aac062", Constant.AAC062_1_RYXCB);

        List<Map<String, Object>> ac50s = accountAc50Service.listMaps(queryWrapper);
        //查询账户
        List<MyMap> ac51s = new ArrayList<>();
        if (ValidateUtil.isNotEmpty(ac50s)) {

            List<String> aaz116s = ac50s.stream().map(ac50 -> ac50.get("aaz116").toString()).collect(Collectors.toList());
            QueryWrapper<AccountAc51> queryac51Wrapper = new QueryWrapper<>();
            queryac51Wrapper.eq("aaz159", this.transferPersonInfo.getAaz159());
            queryac51Wrapper.eq("aac001", this.transferPersonInfo.getAac001());
            queryac51Wrapper.in("aaz116", aaz116s);

            //查询历年台账
            String aaf018 = "00";//todo 需要根据实际整改
            List ac51List = new ArrayList<>();
            if (aaf018.startsWith("53")) {

//                    ac51List = MiddleAccountLightRegister.getIMiddleAccountPublicQueryLight().getAC51A4(param);
                ac51List = new ArrayList<>();
            } else {
                ac51List = accountAc51Service.listMaps(queryac51Wrapper);

            }


            if (ValidateUtil.isNotEmpty(ac51List)) {
                ac51s.addAll(transferInformationService.convertAc51(ac51List));
                /*MyMap dealMap = new MyMap();
                dealMap.put("save", "save");
                dealMap.put("aaz159", this.transferPersonInfo.getAaz159());
                dealMap.put("aac001", this.transferPersonInfo.getAac001());
                this.transOutDeal = TransferFactory.getTransOutDeal(dealMap);
                BigDecimal aae206 = this.transferPersonInfo.getAae206();
                ac51s.addAll(this.transOutDeal.getNewAc51s(ac51List, ListUtil.list2MyMapList(this.paymentList), aae206));*/
                /*MyMap dealMap = new MyMap();
                dealMap.put("save", "save");
                dealMap.put("aaz159", this.transferPersonInfo.getAaz159());
                dealMap.put("aac001", this.transferPersonInfo.getAac001());
                this.transOutDeal = TransferFactory.getTransOutDeal(dealMap);
                BigDecimal aae206 = this.transferPersonInfo.getAae206();
                ac51s.addAll(this.transOutDeal.getNewAc51s(ac51List, ListUtil.list2MyMapList(this.paymentList), aae206));*/
            }
        }
        List<Map> ac08List = this.paymentList;
        NPETool.isEmptyThrowException(ac08List, "缴费明细");
        //预缴处理，把费款期当做到账日期
        if (!ValidateUtil.isEmpty(ac08List)) {
            for (Map map : ac08List) {
                if (map.get("aae003").toString().compareTo(map.get("aab191").toString().substring(0, 6)) > 0) {
                    map.put("aab191", map.get("aae003") + "01");
                }
            }
        }
        List<MyMap> ac08s = new ArrayList<>();
        for (Map ac08Map : ac08List) {
            ac08s.add(new MyMap(ac08Map));
        }
        // 组装信息表明细
        List<Ic91Info> payments = transferInformationService.matchPaymentAndAccount(ac08s, ac51s, transferPersonInfo);
        //组装信息表表头
        Ic90Info ic90Info = transferInformationService.createTransferFund(payments, ac08s, transferPersonInfo);
        //处理退役军人补缴往年的情况:累计存储额不变，基数比例记账金额按往年基数比例显示
        //deductionMonery3604(payments);

        transferInformationService.deleteAccountBeforeAac032(payments, transferPersonInfo.getAae206(), transferPersonInfo);

        transOutDealService.dealWithAccountBeforeAac032(payments, this.transferPersonInfo, ac08List);

        this.informationDetailInfos.addAll(payments);

        this.informationInfo = ic90Info;
        if(Constant.AIC113_6_JGSYDWYLBXZDNZY.equals(this.aic113)) {
            setInformations53();
        }
    }

    /**
     * 创建信息表
     */
    private void createInformationOfIc66Preview(List<Map> ac51s, List<Map> ac52s) {
        //后台根据账户类型判断 无需前台传入
        this.aae803 = Constant.AAE803_T1102_JGYLBXZYXXB;
        BigDecimal aae206 = this.transferPersonInfo.getAae206();

        List<Map> ac08List = this.paymentList;
        NPETool.isEmptyThrowException(ac08List, "缴费明细");
        List<MyMap> ac08s = new ArrayList<>();
        for (Map ac08Map : ac08List) {
            ac08s.add(new MyMap(ac08Map));
        }

        MyMap dealMap = new MyMap();
        dealMap.put("save", "save");
        dealMap.put("aaz159", this.transferPersonInfo.getAaz159());
        dealMap.put("aac001", this.transferPersonInfo.getAac001());
        dealMap.put("aae140", this.transferPersonInfo.getAae140());

        // 组装信息表明细
        List<Ic91Info> payments = transferInformationService.matchPaymentAndAccount(ac08s, transferInformationService.getNewAc51s(ac51s), transferPersonInfo);
        //List<Ic91Info> payments = matchPaymentAndAccount(ac08s, this.transOutDeal.getNewAc51s(ac51s, ac08s, aae206));
        //List<Ic91Info> payments = matchPaymentAndAccount(ac08s, this.transOutDeal.getNewAc51s(ac51s, ac08s, aae206));

        //组装信息表表头
        Ic90Info ic90Info = transferInformationService.createTransferFund(payments, ac08s, transferPersonInfo);
        //处理退役军人补缴往年的情况:累计存储额不变，基数比例记账金额按往年基数比例显示
        deductionMonery3604(payments);

        transferInformationService.deleteAccountBeforeAac032(payments, transferPersonInfo.getAae206(), transferPersonInfo);

        transOutDealService.dealWithAccountBeforeAac032(payments, this.transferPersonInfo, ac08List);

        this.informationDetailInfos.addAll(payments);

        this.informationInfo = ic90Info;
        if(Constant.AIC113_6_JGSYDWYLBXZDNZY.equals(this.aic113)) {
            setInformations53();
        }
    }



    /**
     * 扣减退役军人补缴差额部分
     */
    private void deductionMonery3604(List<Ic91Info> ic91s) {
        //查询缴费记录
        Map q = new HashMap();
        q.put("aac001", this.aac001);
        q.put("aaz159", this.transferPersonInfo.getAaz159());
        q.put("tyjrzhdy", "1");
        q.put("zzzhdy", "1");//终止账户也需要查询打印
        q.put("ynPc06", "1");
        List<Map> payments = accountCommonMapper.queryAc08(q);
        if (ValidateUtil.isNotEmpty(payments)) {
            List<Map> paymentsNew = payments.stream().filter(paymentMap -> Constant.AAE793_3604_TYJRBJCE.equals(paymentMap.get("aae793"))).collect(Collectors.toList());
            if (ValidateUtil.isNotEmpty(paymentsNew)) {
                if (ValidateUtil.isNotEmpty(paymentsNew)) {
                    Map<String, List<Map>> aae001Map = paymentsNew.stream().collect(Collectors.groupingBy(m -> m.get("aab191").toString().substring(0, 4)));
                    deductionMoneryAc51(ic91s, aae001Map);
                }
            }
        }

    }

    /**
     * 循环扣减台帐
     *
     * @param paymentMap
     */
    private void deductionMoneryAc51(List<Ic91Info> ic91s, Map<String, List<Map>> paymentMap) {
        if (ValidateUtil.isEmpty(ic91s)) {
            return;
        }
        if (ValidateUtil.isEmpty(paymentMap)) {
            return;
        }

        List<Map> list;
        // BigDecimal aae381;
        // BigDecimal aae264;

        //退役军人补缴-单位划账户部分
        BigDecimal aae081d;
        //退役君补缴-个人划账户部分
        BigDecimal aae083d;
        for (String aae001 : paymentMap.keySet()) {

            aae081d = BigDecimal.ZERO;
            aae083d = BigDecimal.ZERO;
            list = paymentMap.get(aae001);
            if (ValidateUtil.isNotEmpty(list)) {
                for (Map p : list) {
                    aae081d = aae081d.add(ValidateUtil.isEmpty(p.get("aae081")) ? BigDecimal.ZERO : new BigDecimal(p.get("aae081").toString()));
                    aae083d = aae083d.add(ValidateUtil.isEmpty(p.get("aae083")) ? BigDecimal.ZERO : new BigDecimal(p.get("aae083").toString()));
                }
            }

            for (Ic91Info ic91Info : ic91s) {
                if (!ValidateUtil.isEmpty(ic91Info.getAae001()) && !ValidateUtil.isEmpty(ic91Info.getAae381())) {
                    if (aae001.equals(ic91Info.getAae001().toString())) {

                        ic91Info.setAae381(ic91Info.getAae381().subtract(aae081d).subtract(aae083d));
                        ic91Info.setAae264(ic91Info.getAae264().subtract(aae083d));
                        break;
                    }
                }
            }

        }
    }

    /**
     * 组装人员信息
     *
     * @param transferPerson
     * @param map
     */
    void transferPersonInfoCreate(MyMap transferPerson,MyMap map) {
        transferPersonInfo = new TransferPersonInfo();

        /**
         * 首次参保地缴费时间
         */
        this.aab305 = transferPerson.getAsString("aab305");
        /**
         * 单位编号
         */
        transferPersonInfo.setAab001(transferPerson.getAsBigDecimal("aab001"));
        /**
         * 单位名称
         */
        transferPersonInfo.setAab004(transferPerson.getAsString("aab004"));
        /**
         * 人员编号
         */
        ;
        transferPersonInfo.setAac001(transferPerson.getAsBigDecimal("aac001"));
        /**
         * 社会保障号
         */
        transferPersonInfo.setAac002(transferPerson.getAsString("aac002"));
        /**
         * 姓名
         */
        ;
        transferPersonInfo.setAac003(transferPerson.getAsString("aac003"));
        /**
         * 性别
         */
        transferPersonInfo.setAac004(transferPerson.getAsString("aac004"));
        /**
         * 出生日期
         */
        transferPersonInfo.setAac006(transferPerson.getAsBigDecimal("aac006"));
        /**
         * 参加工作日期
         */
        transferPersonInfo.setAac007(transferPerson.getAsBigDecimal("aac007"));
        /**
         * 户口性质（户籍地类别）
         */
        transferPersonInfo.setAac009(transferPerson.getAsString("aac009"));
        /**
         * 户口所在地址
         */
        transferPersonInfo.setAac010(transferPerson.getAsString("aac010"));
        /**
         * 手机号码
         */
        transferPersonInfo.setAac067(transferPerson.getAsString("aac067"));
        /**
         * 农民工标识
         */
        ;
        transferPersonInfo.setAac028(transferPerson.getAsString("aac028"));
        /**
         * 人员参保关系ID
         */
        transferPersonInfo.setAaz159(transferPerson.getAsBigDecimal("aaz159"));
        /**
         * 个人参保日期
         */
        transferPersonInfo.setAac030(transferPerson.getAsBigDecimal("aac030"));
        /**
         * 参保险种
         */
        transferPersonInfo.setAae140(transferPerson.getAsString("aae140"));
        /**
         * 人员账户类别
         */
        transferPersonInfo.setAae473(transferPerson.getAsString("aae473"));
        /**
         * 统筹区
         */
        transferPersonInfo.setAaa027(transferPerson.getAsString("aaa027"));

        /**
         * 参保机构
         */
        transferPersonInfo.setAab359(map.getAsString("aab359"));
        /**
         * 首次参保年月
         */
        transferPersonInfo.setAac049(transferPerson.getAsBigDecimal("aac049"));

        /**
         * 建立账户年月
         */
        transferPersonInfo.setAae206(transferPerson.getAsBigDecimal("aae206"));

        /**
         * 用工形式
         */
        transferPersonInfo.setAac013(transferPerson.getAsString("aac013"));

        this.aab305 = transferPerson.getAsString("aab305");

        Map orginfoin = (Map) map.get("orginfoin");
        if (!ValidateUtil.isEmpty(orginfoin)) {//转入机构信息从联系函获取
            transferPersonInfo.setAab299(orginfoin.get("aab301").toString());
            if(ValidateUtil.isEmpty(orginfoin.get("aae270")) ){//预览的时候不一定有联系函编号
                Sequence sequence_aae270 = new Sequence();
                sequence_aae270.setName("aae270");
                transferPersonInfo.setAae270(sequenceService.nextSequence(sequence_aae270));
            }else{
            transferPersonInfo.setAae270(orginfoin.get("aae270").toString());

            }
        }
        transferPersonInfo.setAae011(map.getAsString("aae011"));

    }



    private void setInformations53() {
            Ic90Info ic66Info = new Ic90Info(MyMap.convertToMap(informationInfo));
            ic66Info.setAic113(this.aic113);
            this.informationInfo = ic66Info;

            List<Ic91Info> ic91Infos = new ArrayList<>();
            List<Ic68Info> ic68Infos = new ArrayList<>();
            Ic91Info ic91Info;
            for (InformationDetailInfo informationDetailInfo : informationDetailInfos) {
                ic91Info = new Ic91Info(MyMap.convertToMap( informationDetailInfo));
                ic91Infos.add(ic91Info);
            }
            this.informationDetailInfos.clear();
            this.informationDetailInfos.addAll(ic91Infos);
            if (Constant.AIC113_6_JGSYDWYLBXZDNZY.equals(this.aic113)) {


                List<Map<String, Object>> aa02List = accountAa02Service.listMaps();
                NPETool.isEmptyThrowException(aa02List, "社平工资参数");

                aa02List = aa02List.stream().filter(aa02 -> Constant.AAA021_2_SJ.equals(aa02.get("aaa021")) && Constant.BAA010_SP100_ZJSPGZ100.equals(aa02.get("baa010"))).collect(Collectors.toList());
                NPETool.isEmptyThrowException(aa02List, "社平工资参数");

                Map<String, List<InformationDetailInfo>> groupMap = informationDetailInfos.stream().collect(Collectors.groupingBy(info -> ((Ic91Info) info).getAae001().toString().substring(0,4)));
                Ic68Info ic68Info;
                MyMap aa02Map = null;

                List<InformationDetailInfo> infosAae001;
                Integer minAae041 = 9999;
                Integer maxAae042 = 0;
                for (String aae001 : groupMap.keySet()) {
                    infosAae001 = groupMap.get(aae001);
                    for (InformationDetailInfo detailInfo : infosAae001) {
                        BigDecimal aae180 = BigDecimal.ZERO;
                        BigDecimal aae202 = BigDecimal.ZERO;
                        BigDecimal mouth = BigDecimal.ZERO;
                        Integer aae041 = 999999;
                        Integer aae042 = 0;

                        if (aae041 > ((Ic91Info) detailInfo).getAae041().intValue()) {
                            aae041 = ((Ic91Info) detailInfo).getAae041().intValue();
                        }
                        if (aae042 < ((Ic91Info) detailInfo).getAae042().intValue()) {

                            aae042 = ((Ic91Info) detailInfo).getAae042().intValue();
                        }

                        if (minAae041 > Integer.parseInt(((Ic91Info) detailInfo).getAae041().toString().substring(0,4))) {
                            minAae041 = Integer.parseInt(((Ic91Info) detailInfo).getAae041().toString().substring(0,4));
                        }
                        if (maxAae042 < Integer.parseInt( ((Ic91Info) detailInfo).getAae042().toString().substring(0,4))) {
                            maxAae042 =Integer.parseInt( ((Ic91Info) detailInfo).getAae042().toString().substring(0,4));
                        }

                        mouth = (((Ic91Info) detailInfo).getAae042()).subtract(((Ic91Info) detailInfo).getAae041()).add(BigDecimal.ONE);
                        aae202 = aae202.add(ValidateUtil.isEmpty(((Ic91Info) detailInfo).getAae202()) ? BigDecimal.ZERO : ((Ic91Info) detailInfo).getAae202());
                        aae180 = aae180.add(ValidateUtil.isEmpty(((Ic91Info) detailInfo).getAae180()) ? BigDecimal.ZERO : ((Ic91Info) detailInfo).getAae180()
                                .multiply( (((Ic91Info) detailInfo).getAae042()).subtract(((Ic91Info) detailInfo).getAae041()).add(BigDecimal.ONE)));

                        Integer tempAae001 = Integer.valueOf(aae041.toString().substring(0,4)) - 1;
                        for (Map m : aa02List) {

                            if (tempAae001.equals(NumberUtil.bigDecimal2Integer(m.get("aae001")))) {
                                aa02Map = new MyMap(m);
                                break;
                            }
                        }
                        if (ValidateUtil.isEmpty(aa02Map)) {
                            throw new IllegalArgumentException("没有获取到" + aae001 + "社平工资参数");
                        }
                        ic68Info = new Ic68Info();
                        ic68Info.setAab301(ic66Info.getAab301());
                        ic68Info.setAac319(ic66Info.getAac319());
                        ic68Info.setAae001(new BigDecimal(Integer.parseInt(aae041.toString().substring(0, 4))));

                        ic68Info.setAae041(new BigDecimal(aae041));
                        ic68Info.setAae042(new BigDecimal(aae042));
                        ic68Info.setAaa015(aa02Map.getAsBigDecimal("aaa010"));
                        if (BigDecimal.ZERO.compareTo(aae180) < 0) {
                            ic68Info.setAae180(aae180.divide(mouth, 2, BigDecimal.ROUND_HALF_UP));
                        } else {
                            ic68Info.setAae180(BigDecimal.ZERO);
                        }

                        if (aae180.compareTo(BigDecimal.ZERO) > 0) {//1先取有月数的
                            ic68Infos.add(ic68Info);
                        }


                    }

                }


                Map<String, List<Ic68Info>> ic68 = ic68Infos.stream().collect(Collectors.groupingBy(map -> map.getAae041().toString()+map.getAae042().toString()));

                List<Ic68Info> ic68s= new ArrayList<>();
                // 获取所有的key并转换成Integer
                List<String> keysAsIntegers = ic68.keySet().stream().collect(Collectors.toList());

                for (String keysAsInteger : keysAsIntegers) {
                    List<Ic68Info> ic68Infos1 = ic68.get(keysAsInteger);
                    if(ic68Infos1.size()>0){
                        BigDecimal aae180_add=BigDecimal.ZERO;

                        for (Ic68Info info : ic68Infos1) {
                            aae180_add = aae180_add.add(info.getAae180());

                        }
                        Ic68Info ic68Info1 = new Ic68Info();
                        ic68Info1.setAab301(ic68Infos1.get(0).getAab301());
                        ic68Info1.setAac319(ic68Infos1.get(0).getAac319());
                        ic68Info1.setAae001(ic68Infos1.get(0).getAae001());
                        ic68Info1.setAae041(ic68Infos1.get(0).getAae041());
                        ic68Info1.setAae042(ic68Infos1.get(0).getAae042());
                        ic68Info1.setAae180(aae180_add);
                        ic68Info1.setAaa015(ic68Infos1.get(0).getAaa015());

                        ic68s.add(ic68Info1);


                    }

                }

                //存在中断的年度 需要补全信息表附表的信息
                List<BigDecimal> aae001s = new ArrayList<>();
                ic68s.stream().forEach(ic -> {
                    aae001s.add(ic.getAae001());
                });
                List<BigDecimal> aae001MyLits = new ArrayList<>();
                for (int i = minAae041; i <= maxAae042; i++) {
                    aae001MyLits.add(new BigDecimal(i));
                }
                List<BigDecimal> fitterList = aae001MyLits.stream().filter(aae001 -> !aae001s.contains(aae001)).collect(Collectors.toList());

                List<Ic68Info> ic68Infos2 = new ArrayList<>();
                //2、查询没有的再补上
                for (int i = 0; i < fitterList.size(); i++) {
                    String s = fitterList.get(i).toString();

                    for (Map m : aa02List) {
                        if (Integer.parseInt(s+"06")>= Integer.valueOf(m.get("aae041").toString()) && (ValidateUtil.isEmpty(m.get("aae042")) || Integer.parseInt(s+"12") <= Integer.valueOf(m.get("aae042").toString()))) {
                            aa02Map = new MyMap(m);
                            break;
                        }
                    }
                    ic68Info = new Ic68Info();
                    ic68Info.setAab301(ic66Info.getAab301());
                    ic68Info.setAac319(ic66Info.getAac319());
                    ic68Info.setAae001(new BigDecimal(s));
                    ic68Info.setAae041(new BigDecimal(s + "12"));
                    ic68Info.setAae042(new BigDecimal(s + "12"));
                    ic68Info.setAaa015(aa02Map.getAsBigDecimal("aaa010"));
                    ic68Info.setAae180(BigDecimal.ZERO);
                    ic68Infos2.add(ic68Info);
                }

                this.informationOtherInfos.addAll(ic68s);
                this.informationOtherInfos.addAll(ic68Infos2);
            }
        }
    }

